package com.aquarium.ui.controller;

import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.aquarium.R;

public class TimePickListViewAdapter extends SimpleCursorAdapter {

	public final static String AM_PM_STRING_KEY = "AM_PM_STRING_KEY";
	public final static String AM_STRING_VALUE = "AM";
	public final static String PM_STRING_VALUE = "PM";

	private CheckBoxStatusChangedListener mCheckBoxListener;

	public TimePickListViewAdapter(Context context, int layout, Cursor c,
			String[] from, int[] to) {
		super(context, layout, c, from, to);
	}

	public interface CheckBoxStatusChangedListener {
		void onChanged(int pos, boolean isChecked);
	}

	public void setCheckBoxStatusChangedListener(CheckBoxStatusChangedListener l) {
		mCheckBoxListener = l;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		View v = super.getView(position, convertView, parent);
		CheckBox cb = (CheckBox) v.findViewById(R.id.del_ckbox);
		cb.setChecked(false);
		cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				if (mCheckBoxListener != null) {
					mCheckBoxListener.onChanged(position, isChecked);
				}
			}
		});

		return v;
	}

}
